home *** CD-ROM | disk | FTP | other *** search
- /*
- ** universal code (ucode)
- */
-
- #pragma once
-
- struct ucode
- {
- unsigned char *text, *data, *bss, *stack, *exstack; /* code segments */
- unsigned char *textend, *dataend, *bssend, *stackend, *exend; /* end of segments */
- unsigned long *pc; /* program pointer */
- unsigned long *sp; /* call, args, auto stack pointer */
- unsigned long *tos; /* expression stack */
- };
-
- enum { /* opcodes in upper 8 bits of command */
- /* constants */
- OPC_CONST=0, /* 24 bit positive constant */
- OPC_NCONST, /* 24 bit negative constant */
- OPC_HCONST, /* 24 bit high part of constant added to tos */
- OPC_TEXT=8, /* 24 bit offset into text segment */
- OPC_DATA, /* 24 bit offset into data segment */
- OPC_BSS, /* 24 bit offset into bss segment */
- /* program flow */
- OPC_CALL=0x10, /* call tos */
- OPC_JMP, /* jmp to tos */
- OPC_JTRUE, /* jump to tos if nos true */
- OPC_JFALSE, /* jump to tos if nos false */
- OPC_RET, /* return */
- OPC_SETJMP, /* set jump (tos=addr of jmpbuf) */
- OPC_LONGJMP, /* long jump (tos=addr of jmpbuf) */
- /* switch/case program flow */
- OPC_SWITCHSRCH, /* search table for switch */
- OPC_SWITCHJMP, /* jmp table for switch */
- /* stack manipulation */
- OPC_PUSH=0x20, /* push tos on stack */
- OPC_POP, /* pop from stack */
- OPC_ALLOC, /* allocate/deallocate space stack */
- OPC_AUTO, /* make stack offset */
- /* binary arithmetic and logical operations */
- OPC_ADD=0x30,
- OPC_SUB,
- OPC_MUL,
- OPC_UMUL,
- OPC_DIV,
- OPC_UDIV,
- OPC_MOD,
- OPC_UMOD,
- OPC_AND,
- OPC_OR,
- OPC_XOR,
- /* binary shift operations */
- OPC_SHL=0x40,
- OPC_USHL,
- OPC_SHR,
- OPC_USHR,
- /* binary compare operations */
- OPC_LT=0x50,
- OPC_ULT,
- OPC_GT,
- OPC_UGT,
- OPC_LE,
- OPC_ULE,
- OPC_GE,
- OPC_UGE,
- OPC_EQ,
- OPC_NEQ,
- /* unary operations */
- OPC_EQZ=0x60,
- OPC_NZ,
- OPC_NEG,
- OPC_NOT,
- OPC_CHS,
- OPC_SHIFT, /* multiply by 2 - for fast index calculations */
- OPC_SEXTB, /* sign extend byte -> long */
- OPC_SEXTW, /* sign extend word -> long */
- /* working stack manipulation */
- OPC_DUP=0x70, /* duplicate value */
- OPC_SWAP, /* swap tos and nos */
- OPC_DROP, /* throw away value */
- OPC_NDUP, /* duplicate n-th value */
- /* store to memory */
- OPC_STOREB=0x80,
- OPC_STOREW,
- OPC_STOREL,
- OPC_STOREF,
- OPC_STORED,
- /* fetch from memory */
- OPC_FETCHB=0x90,
- OPC_FETCHW,
- OPC_FETCHL,
- OPC_FETCHF,
- OPC_FETCHD,
- OPC_UFETCHB,
- OPC_UFETCHW,
- OPC_UFETCHL,
- /* floating point operations */
- OPC_FADD=0xa0, /* dyadic */
- OPC_FSUB,
- OPC_FMUL,
- OPC_FDIV,
- OPC_FNEG=0xb0, /* monadic */
- OPC_ITOF, /* integer to double */
- OPC_FTOI, /* double to integer */
- /* system call */
- OPC_SVC=0xc0, /* supervisor call */
- /* builtin functions */
- OPC_CPYINC, /* block copy with inc mode */
- OPC_CPYDEC, /* block copy with dec mode */
- OPC_SET, /* set block */
- OPC_SRCH /* search in block */
- };
-
- void run(struct ucode *c, register long n);
-
- /* EOF */